<template>
  <div id="testlistpanel">
    <vxe-toolbar class-name="bg-orange light">
      <template #buttons>
        <span class="padding-lr-xs">
          <vxe-button type="text" :loading="loading" content="刷新" class-name="padding-lr-xs"
            class="button-blue padding-lr-xs" @click="searchConfirm" />
          <vxe-button type="text" content="删除" class-name="padding-lr-xs " class="button-red padding-lr-xs margin-left-xs"
            @click="deleteMainInfo" />
        </span>
        <el-popover :visible="showPull" placement="bottom" :width="360">
          <template #reference>
            <vxe-button type="text" icon="vxe-icon-funnel" content="筛选" class-name="padding-lr-xs"
              class="button-blue padding-lr-xs" @click="showPull = !showPull" />
          </template>

          <template #default>
            <div class="my-dropdown3 padding-xs border">
              <div class="text-bold padding-bottom">筛选条件</div>

              <vxe-form class-name="padding-lr-xs">
                <vxe-form-item span="24" title="病历号" title-width="70">
                  <template #default>
                    <vxe-input v-model="searchForm.patNo" placeholder="病历号" type="text" class="vxeInputSearch"
                      style="margin-left: 5px;"></vxe-input>
                  </template>
                </vxe-form-item>
                <vxe-form-item span="24" title="姓名" title-width="70">
                  <template #default>
                    <vxe-input v-model="searchForm.patNa" placeholder="姓名" type="text" class="vxeInputSearch"
                      style="margin-left: 5px;"></vxe-input>
                  </template>
                </vxe-form-item>
                <vxe-form-item span="24" title="病人类型" title-width="70">
                  <template #default>
                    <vxe-select style="width: 100%" class-name="margin-lr-xs" v-model="selPatType" placeholder="类型">
                      <vxe-option v-for="(item, index) in patTypeList" :key="index" :value="item.code"
                        :label="item.name"></vxe-option>
                    </vxe-select>
                  </template>
                </vxe-form-item>
                <vxe-form-item span="24" title="审核标志" title-width="70">
                  <template #default>
                    <vxe-select style="width: 100%" class-name="margin-lr-xs" v-model="state" placeholder="状态">
                      <vxe-option v-for="(item, index) in stateOpts" :key="index" :value="item.value"
                        :label="item.label"></vxe-option>
                    </vxe-select>
                  </template>
                </vxe-form-item>
                <vxe-form-item span="24" title="标本类型" title-width="70">
                  <template #default>
                    <vxe-select style="width: 100%" class-name="margin-lr-xs" v-model="searchForm.sampleType"
                      placeholder="标本类型">
                      <vxe-option v-for="(item, index) in sampleTypeList" :key="index" :value="item.sampleTypeCode"
                        :label="item.sampleTypeName"></vxe-option>
                    </vxe-select>
                  </template>
                </vxe-form-item>
                <vxe-form-item span="24" title="检验目的" title-width="70">
                  <template #default>
                    <vxe-select style="width: 100%" class-name="margin-lr-xs" v-model="searchForm.reqPurposeId"
                      placeholder="检验目的">
                      <vxe-option v-for="(item, index) in reqPurposeList" :key="index" :value="item.id"
                        :label="item.purposeName"></vxe-option>
                    </vxe-select>
                  </template>
                </vxe-form-item>
                <vxe-form-item span="24" title="审核日期" title-width="70">
                  <vxe-input v-model="searchForm.chkTimeS" placeholder="开始日期" type="date" transfer
                    style="width: 116px;margin-left: 5px"></vxe-input>
                  <div style="display: inline-block">-</div>
                  <vxe-input v-model="searchForm.chkTimeE" placeholder="结束日期" type="date" transfer
                    style="width:116px"></vxe-input>
                </vxe-form-item>

                <vxe-form-item span="24" title="我的报告" title-width="70">
                  <template #default>
                    <vxe-checkbox content="" v-model="isSelfRpt" :checked-value="1" :unchecked-value="0"
                      style="margin-left: 5px"></vxe-checkbox>
                  </template>
                </vxe-form-item>
                <vxe-form-item span="24" title="生化实验" title-width="70">
                  <template #default>
                    <vxe-checkbox content="" v-model="searchForm.isExperiment" :checked-value="1" :unchecked-value="0" style="margin-left: 5px"></vxe-checkbox>
                  </template>
                </vxe-form-item>
                <vxe-form-item span="24" title="是否阳性" title-width="70">
                  <template #default>
                    <vxe-select style="width: 100%" class-name="margin-lr-xs" v-model="searchForm.isPositive"
                      placeholder="标本类型">
                      <vxe-option :value="'1'" :label="`全部`"></vxe-option>
                      <vxe-option :value="'2'" :label="`阳性`"></vxe-option>
                      <vxe-option :value="'3'" :label="`阴性`"></vxe-option>
                    </vxe-select>
                  </template>
                </vxe-form-item>
                <vxe-form-item span="24" title="是否染色项目" title-width="70">
                  <template #default>
                    <vxe-select style="width: 100%" class-name="margin-lr-xs" v-model="searchForm.isStaining"
                      placeholder="">
                      <vxe-option :value="'2'" :label="`全部`"></vxe-option>
                      <vxe-option :value="'0'" :label="`否`"></vxe-option>
                      <vxe-option :value="'1'" :label="`是`"></vxe-option>
                    </vxe-select>
                  </template>
                </vxe-form-item>
                <vxe-form-item span="24" title="查询最近天数" title-width="70">
                  <template #default>
                    <vxe-select style="width: 100%" class-name="margin-lr-xs" v-model="searchForm.queryDay"
                      placeholder="">
                      <vxe-option :value="null" :label="`全部`"></vxe-option>
                      <vxe-option :value="0" :label="`今天`"></vxe-option>
                      <vxe-option :value="1" :label="`昨天`"></vxe-option>
                      <vxe-option :value="2" :label="`前天`"></vxe-option>
                      <vxe-option :value="58" :label="`5-8天`"></vxe-option>
                    </vxe-select>
                  </template>
                </vxe-form-item>
              </vxe-form>

              <div class="margin-top flex justify-end">
                <span class="padding-lr-xs">
                  <vxe-button type="text" content="重置" class-name="padding-lr-xs" class="button-blue padding-lr-xs"
                    @click="searchAll" />
                  <vxe-button type="text" content="确定" class-name="padding-lr-xs" class="button-blue padding-lr-xs"
                    @click="searchConfirm" />
                  <vxe-button type="text" status="primary" content="取消" class="button-blue padding-lr-xs"
                    @click="closeShowPull"></vxe-button>
                </span>
              </div>
            </div>
          </template>
        </el-popover>
        &nbsp;&nbsp;&nbsp;
        <span>登记日期：</span>
        <vxe-input v-model="searchForm.testTimeS" placeholder="开始日期" type="date" transfer
          style="width: 116px;margin-left: 5px"></vxe-input>
        <div style="display: inline-block">-</div>
        <vxe-input v-model="searchForm.testTimeE" placeholder="结束日期" type="date" transfer style="width:116px"></vxe-input>
        &nbsp;&nbsp;&nbsp;
        <vxe-button type="text" icon="vxe-icon-search" class="button-blue SearchBtn" content="查询"
          @click="searchConfirm"></vxe-button>
      </template>
    </vxe-toolbar>
    <div
      :style="{ height: isShowItemTemplatePanel ? 'calc(100% - 30px - 40px - 2px)' : 'calc(100% - 30px - 40px - 2px - 21px)' }">
      <vxe-table show-overflow keep-source resizable ref="tableTestListRef" height="auto" :cell-style="cellClassName"
        :header-cell-style="{ height: '35px', padding: '0px 2px' }"
        :sort-config="{ iconAsc: 'vxe-icon-arrow-up', iconDesc: 'vxe-icon-arrow-down' }" :loading="loading"
        :data="labMainInfoList" :menu-config="rightMenuConfig" :keyboard-config="{ isArrow: true }"
        :row-config="{ height: wlRowHeight, isCurrent: true, isHover: true }"
        :edit-config="{ trigger: 'click', mode: 'row', showStatus: true }" :scroll-y="{ enabled: true }"
        @menu-click="contextMenuClickEvent" align="center" border @current-change="handleRowClick">
        <!-- <vxe-column type="seq" width="30" title="#" fixed="left"></vxe-column> -->
        <vxe-column width="16" fixed="left">
          <template #default="{ row }">
            <span style="width: 12px; height: 12px; display: inline-block; border-radius: 50%"
              :style="{ backgroundColor: row.mandatoryManualReview ? 'red' : row.autoVerification && row.autoVerificationManualReview ? '#fbbd08' : row.autoVerification && row.autoVerificationAutoReview ? '#39b54a' : '' }"></span>
          </template>
        </vxe-column>
        <vxe-column class-name="flag-cell" :field="colitem.fieldCode" :title="colitem.fieldName"
          :sortable="colitem.isSortable === 1" :fixed="colitem.isFix === 1 ? 'left' : ''"
          :align="!colitem.align ? 'left' : colitem.align" :header-align="!colitem.align ? 'left' : colitem.align"
          :width="colitem.columnWidth" v-for="(colitem, index) in testListColumns.filter((data) => data.isVisiable == 1)"
          :key="index">
          <template #header
            v-if="colitem.fieldCode === 'isUrgent' || colitem.fieldCode === 'isPrint' || colitem.fieldCode === 'isAutoPrint' || colitem.fieldCode === 'isChk' || colitem.fieldCode === 'isAlarm'">
            <span style="font-size: 300">{{ colitem.fieldName }}</span>
          </template>
          <template #default="{ row }">
            <span v-if="colitem.fieldCode === 'isUrgent' && row.isUrgent === 1" class="el-icon-first-aid-kit">
              <el-icon>
                <WarnTriangleFilled />
              </el-icon>
            </span>
            <i v-else-if="colitem.fieldCode === 'isPrint' && row.isPrint === 1" class="el-icon-printer">
              <el-icon>
                <Printer />
              </el-icon>
            </i>
            <i v-else-if="colitem.fieldCode === 'isAutoPrint' && row.isAutoPrint === 1" class="el-icon-s-platform">
              <el-icon>
                <Monitor />
              </el-icon>
            </i>
            <i v-else-if="colitem.fieldCode === 'isChk' && row.isChk === 1" class="el-icon-s-check">
              <span style="color: #fff">初</span>
            </i>
            <i v-else-if="(colitem.fieldCode === 'isChk' && row.isChk === 2) || (colitem.fieldCode === 'isChk' && row.isChk === 1)"
              class="el-icon-finished">
              <el-icon>
                <SuccessFilled />
              </el-icon>
            </i>
            <el-tooltip v-if="colitem.fieldCode === 'criticalValueInfo' && row.criticalValueInfo" effect="dark"
              :content="row.criticalValueInfo" placement="top">
              <i class="el-icon-warning"></i>
            </el-tooltip>
            <i v-else-if="colitem.fieldCode === 'isAlarm' && row.isAlarm === 1" class="el-icon-warning">
              <el-icon>
                <WarningFilled />
              </el-icon>
            </i>
            <i v-else-if="colitem.fieldCode === 'isMdr' && row.isMdr === 1" class="el-icon-warning">
              <el-icon>
                <WarningFilled />
              </el-icon>
            </i>
            <i v-else-if="colitem.fieldCode === 'addFee' && (row.addFee === 1 || row.addFee === 0 || row.addFee == 2)"
              class="el-icon-warning">
              <el-icon>
                <Plus />
              </el-icon>
            </i>
            <span v-else-if="colitem.fieldCode === 'code'" :style="{ color: row.displayColor }">{{ row.code }}</span>
            <span v-else-if="colitem.fieldCode === 'specCode'" :style="{ color: row.displayColor }">{{ row.specCode
            }}</span>
            <span v-else-if="colitem.fieldCode === 'fullName'" :style="{ color: row.displayColor }">{{ row.fullName
            }}</span>
            <span v-else-if="colitem.fieldCode === 'medicalRecNo'" :style="{ color: row.displayColor }">{{
              row.medicalRecNo }}</span>
            <span v-else-if="colitem.fieldCode === 'visitTypeName'" :style="{ color: row.displayColor }">{{
              row.visitTypeName }}</span>
            <span v-else-if="colitem.fieldCode === 'abnormalFlag'" :style="{ color: 'red' }">{{ row.abnormalFlag }}</span>
            <div v-else-if="colitem.fieldCode === 'totalExistingResults'">
              <el-row>
                <el-col :span="12">
                  <div class="text-blue" style="text-align: right">
                    <span class="text-blue">
                      {{ row.totalExistingResults }}
                    </span>
                    <span style="font-size: 14px">/</span>
                  </div>
                </el-col>
                <el-col :span="12">
                  <span class="text-red" style="margin-left: 4px">
                    {{ row.totalResults }}
                  </span>
                </el-col>
              </el-row>
            </div>
            <span v-else-if="colitem.fieldCode === 'age'">
              {{ `${row[colitem.fieldCode] ? row[colitem.fieldCode] : ''}${row['ageUnit'] ? row['ageUnit'] :
                ''}${row['secAge'] ? row['secAge'] : ''}${row['secAgeUnit'] && row['secAge'] ? row['secAgeUnit'] : ''}` }}
            </span>
            <span v-else>
              {{ colitem.fieldCode === 'isUrgent' || colitem.fieldCode === 'isPrint' || colitem.fieldCode ===
                'isAutoPrint' || colitem.fieldCode === 'isChk' || colitem.fieldCode === 'isAlarm' || colitem.fieldCode ===
                'isMdr' || colitem.fieldCode === 'addFee' ? '' : row[colitem.fieldCode] }}
            </span>
          </template>
        </vxe-column>
      </vxe-table>
    </div>
    <vxe-toolbar class-name="bg-grey light footer-vxe-toolbar">
      <template #buttons>
        <div class="text-cut">
          <span>
            <span class="padding-lr-xs">定位</span>
            <vxe-input placeholder="请输入关键字" v-model="keyValueAnchor" @keydown="keyValueAnchorKeyDown"
              @change="keyValueAnchorChange" clearable />
          </span>
          <span class="text-cut flex justify-start">
            <span class="padding-lr-xs text-bold">合计</span>
            <span class="text-blue">{{ testListStat.t }}</span>
            <span class="padding-lr-xs text-bold">已审</span>
            <span class="text-green">{{ testListStat.chkNum.length }}</span>
            <span class="padding-lr-xs text-bold">未审</span>
            <span class="text-grey">{{ testListStat.fChkNum.length }}</span>
          </span>
        </div>
      </template>
    </vxe-toolbar>
    <TestListEdit ref="testListEditRef" @uptSuccess="mainInfoUptSuccess" />
    <TestListBatchHandle ref="testListBatchHandleRef" @uptSuccess="mainInfoBatchUptSuccess" />
  </div>
</template>
<script lang="ts" setup>
import { reactive, ref, getCurrentInstance, onMounted, watch, provide, toRefs, computed } from 'vue';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage';
import { IsEmpty, formatDateTime } from '@/utils/common';
import { stateOptions, testListRightMenus, mainInfoSort, color31 } from './TestListBacUtils.ts';
import { VXETable, VxeFormPropTypes, VxeFormInstance } from 'vxe-table';
import { LabMainInfoColumns } from '@/utils/LabMainInfoColumns';
import { clear } from 'xe-utils';
import { LabMainInfoFields } from '@/utils/LabMainInfoFields';
import { AppStore } from '@/stores/store';
import { BasicDicts } from '@/stores/basicdicts';
import { getOptionValueByCodeRptGroupOption, getOptionValueByCodeGlobalOption } from '@/utils/SysOptionsHelper';
import XEClipboard from 'xe-clipboard';
import { Splitpanes, Pane } from 'splitpanes';
import TestListEdit from '@/views/lab_sys/lab_bus/components/TestListEdit.vue'; /**编辑标本号窗体 */
import TestListBatchHandle from '@/views/lab_sys/lab_bus/components/TestListBatchHandle.vue'; /**批量操作窗体 */
import moment from 'moment';
import { resolve } from 'dns';
import { saveProcessLogs } from '@/utils/BacProcessLogHelper';

const storeObj = AppStore();
const bdstoreObj = BasicDicts(); /**基础字典缓存对象 */
let { proxy }: any = getCurrentInstance();

//#region  Interface
interface PrimaryFormData {
  rptGroup: string;
  sampleda: string;
  sampleNo: string;
  reqNo: string;
}
//#endregion

//#region  属性
let props = defineProps({
  formObj: { type: Object as PropType<PrimaryFormData>, default: { rptGroup: '', sampleda: '', sampleNo: '', reqNo: '' } as PrimaryFormData }
});
//#endregion

//#region  计算属性
let testListStat = computed(() => {
  return { t: labMainInfoList.length, chkNum: labMainInfoList.filter((p) => p.isChk === 2), fChkNum: labMainInfoList.filter((p) => p.isChk === 1) };
});
let patTypeList = computed(() => {
  const a = Object.assign([], bdstoreObj.patTypeList);
  a.unshift({ code: null, name: '全部' });
  return a;
});
//#endregion

//#region  属性监听
watch(
  () => props.formObj,
  (n, o) => {
    //ToDo
  },
  { immediate: true, deep: true }
);
watch(
  () => storeObj.mergeTestListFinish,
  (n, o) => {
    //ToDo
    if (!IsEmpty(n)) {
      refreshMainInfoList();
    }
  },
  { immediate: true, deep: true }
);
//#endregion

const rightMenuConfig = ref(
  testListRightMenus(proxy, ({ options, column, row }) => {
    if (tableTestListRef.value) {
      tableTestListRef.value?.setCurrentRow(row);
      tableTestListRef.value?.focus();
      handleRowClick({ row });
    }
    const isDisabled = !column;
    options.forEach((list: any) => {
      list.forEach((item: any) => {
        item.disabled = isDisabled;
      });
    });
  })
);
const color31Array = reactive(color31());
const stateOpts = ref(stateOptions());
//const patTypeList = reactive(findLocalPatTypeListWithAll());
let state = ref(0);
let selPatType = ref(null);
let isSelfRpt = ref(0);
let labMainInfoList = reactive([]); //申请报告列表
let loading = ref(false);
let showPull = ref(false);
let wlRowHeight = ref(24); //行高
let form = reactive({
  id: '',
  sampleda: '',
  sampleNo: '',
  reqNo: '',
  rptGroup: ''
}) as any;

let searchForm = reactive({
  patNo: '',
  patNa: '',
  sampleType: '',
  reqPurposeId: '',
  testTimeS: moment().subtract(10, 'days').format('YYYY-MM-DD'),
  testTimeE: moment().format('YYYY-MM-DD'),
  chkTimeS: '',
  chkTimeE: '',
  isFilter: false,
  isExperiment: 0,
  isPositive: '1',
  isStaining: '2',
  queryDay: null
}) as any;
let searchConditionObj = reactive({}) as any;
let testListColumns = reactive([]); /*检验列表列顺序*/
let isShowItemTemplatePanel = ref(false); /**是否显示项目模板面板 */
let tableTestListRef = ref(null);
let keyValueAnchor = ref(''); //锚点定位关键字
let anchorKeyDownCount = ref(0); //锚点定位执行回车的次数

const testListEditRef = ref(null); /**编辑检验记录 */
const testListBatchHandleRef = ref(null); /**批量操作组件对象 */
// 方法定义区 =============
defineExpose({
  initPage,
  addMaininfo,
  baseInfoChange /*报告单元、检验日期、标本号、条码号改变后调用函数*/,
  updateMainInfoRow /*检验记录信息有变化，更新函数*/,
  refreshMainInfoListM2,
  refreshMainInfoListM3 /**授权成功后,更新检验记录 */,
  refreshMainInfoListM4 /**检验结果手动改变时调用 */,
  unChkMainInfo /** 取消审核*/,
  getCurrentRecordRow /** 获取当前选中行*/,
  nextRowSelected /**选中下一行操作 */,
  toggleItemTemplatePanel /**切换项目模板显示隐藏 */,
  getCurrentRecordList /**获取当前检验记录列表 */,
  getgetCurrentRecordListLength /**获取当前检验记录列表记录行数 */,
  isMultiFilterState /**判断当前是否处于条件筛选状态 */,
  findLabMainInfoByPrimaryData /**按报告单元，检验日期，标本号查询数据库有没有记录 */,
  timeChangeSetSelectItem /**切换日期，选中当天的第一条记录 */,
  getAddFeeCnt,
  wlRowHeight(res: any) {
    if (!IsEmpty(res)) {
      wlRowHeight.value = res;
    }
  }
});

/**获取检验记录列表 列顺序配置 */
function getFieldsConfigList(rptGroup: any) {
  testListColumns.length = 0;
  if (IsEmpty(rptGroup)) {
    testListColumns.push(...LabMainInfoColumns());
  } else {
    const url = '/lab/wlConfig/findWlConfigByRptGroup';
    const data = {
      suitModule: '2',
      rptGroup: rptGroup,
      type: 3
    };
    proxy.$http
      .get(url, { params: data })
      .then((res: any) => {
        if (res.data.length > 0) {
          testListColumns.push(...res.data);
        } else {
          testListColumns.push(...LabMainInfoColumns());
        }
      })
      .catch((err: any) => {
        testListColumns.push(...LabMainInfoColumns());
      });
  }
}
/** 接收父组件传值 */
function initPage(repData: any) {
  if (IsEmpty(repData.rptGroup)) {
    return;
  }
  getFieldsConfigList(repData.rptGroup);
  if (repData !== null) {
    Object.assign(form, repData);
  }

  /* 报告 单元系统选项  */
  try {
    const a = getOptionValueByCodeRptGroupOption('wswmrcxsjjlcs');
    if (!IsEmpty(a)) {
      const minDate = formatDateTime(new Date().valueOf() - Number(a) * 24 * 60 * 60 * 1000, 'yyyy-MM-dd');
      searchForm.testTimeS = minDate;
    } else {
      const minDatelse = formatDateTime(new Date().valueOf() - 7 * 24 * 60 * 60 * 1000, 'yyyy-MM-dd');
      searchForm.testTimeS = minDatelse;
    }
  } catch (error) {
    const minDateErr = formatDateTime(new Date().valueOf() - 7 * 24 * 60 * 60 * 1000, 'yyyy-MM-dd');
    searchForm.testTimeS = minDateErr;
  }

  findSampleTypeList();
  findReqPurposeList();
  conditionSelectChange();
}
/** 切换日期,选中当天的第一条上机记录*/
function timeChangeSetSelectItem(selectTime) {
  if (IsEmpty(selectTime)) {
    return;
  }
  form.sampleda = formatDateTime(selectTime, 'yyyy-MM-dd');
  const arr = labMainInfoList.filter((m) => m.sampleda === form.sampleda);
  if (arr && arr.length > 0) {
    /**刷新后自动跳到____标本号 sxhtzdbbh */
    const a = getOptionValueByCodeRptGroupOption('sxhtzdbbh');
    /**刷新后跳到【最后】标本*/
    /* 【暂时不启用】 */
    if (!IsEmpty(a) && (a === '2' || a === 2) && false) {
      const row = arr[arr.length - 1];
      tableTestListRef.value?.setCurrentRow(row);
      tableTestListRef.value?.focus();
      handleRowClick({ row });
    } else {
      const row = arr[0];
      tableTestListRef.value?.setCurrentRow(row);
      tableTestListRef.value?.focus();
      handleRowClick({ row });
    }
  } else {
    //选中最后一个
    /* if (labMainInfoList && labMainInfoList.length > 0) {
      const row = labMainInfoList[labMainInfoList.length - 1];
      tableTestListRef.value?.setCurrentRow(row);
      tableTestListRef.value?.focus();
      handleRowClick({ row });
    } */
    /*查不到检验记录，充值条码号 */
    return false;
  }
}

/**查询当前选中记录是否审核
 */
function getCurrentRecordRow() {
  if (tableTestListRef.value) {
    const row = tableTestListRef.value?.getCurrentRecord();
    return row;
  }
  return null;
}
/**查询当前选中记录是否审核
 */
function getCurrentRecordList() {
  return labMainInfoList;
}
/**获取当前检验记录列表行数 */
function getgetCurrentRecordListLength() {
  return labMainInfoList.length;
}
/**跳转下一个标本
 * @param row 当前行
 * @param updown 【u】上一下【d】下一个
 */
function nextRowSelected(row, updown = 'd') {
  if (tableTestListRef.value) {
    const ci = tableTestListRef.value?.getRowIndex(row);
    if (ci > -1) {
      const nci = updown === 'u' ? ci - 1 : ci + 1;
      if (nci >= 0 && nci <= labMainInfoList.length - 1) {
        const nrow = labMainInfoList[nci];
        tableTestListRef.value?.setCurrentRow(nrow);
        tableTestListRef.value?.focus();
        handleRowClick({ row: nrow });
      }
    }
  }
}
/**【没有上机记录的情况下】
 * 直接添加检验结果/或修改病人信息成功后
 * 刷新上机记录列表
 */
function refreshMainInfoListM2({ isSelCurRow, isRefreshRptResult, mainInfoId }) {
  /**如果是多条件查询，直接走这个 */
  if (isMultiFilterState()) {
    refreshMainInfoListM5(mainInfoId);
    return;
  }
  labMainInfoList.length = 0;
  const url = '/lab/maininfo/findLabMaininfoBac';
  proxy.$http
    .get(url, { params: { rptGroup: form.rptGroup, sampleDaStr: form.sampleda, testTimeS: searchForm.testTimeS, testTimeE: searchForm.testTimeE } })
    .then((res: any) => {
      labMainInfoList.length = 0;
      //labMainInfoList.push(...mainInfoSort(res.data));
      Object.assign(labMainInfoList, mainInfoSort(res.data));
      proxy.$emit('getLabMainInfoList', labMainInfoList);
      proxy.$forceUpdate();
      proxy.$nextTick(async () => {
        if (tableTestListRef.value) {
          await tableTestListRef.value?.reloadData(labMainInfoList);
          const rowNewi = labMainInfoList.findIndex((x) => x.id === mainInfoId);
          if (labMainInfoList.length > 0) {
            if (tableTestListRef.value) {
              handleRowClick({ row: labMainInfoList[rowNewi] });
            }
          }
        }
      });
    })
    .catch((err: any) => {
      VxeMessage('搜索报告申请异常' + err, VxeNotifyType.error);
    });
}
/**授权成功后,审核、更新检验记录
 * @e 更新条件
 */
async function refreshMainInfoListM3(e, isNextRow = true, isTreatPrint = true) {
  /**只修改当前标本 e.edtType===1*/
  /**修改所有未审核标本 e.edtType===2*/
  /**修改指定标本号范围 e.edtType===3*/
  proxy.$emit('IschkLoading', 1);
  let acterCode = '';
  let acterNa = '';
  switch (e.action) {
    case '1':
    case '2':
    case '4':
      acterCode = storeObj && storeObj.chkDoctorObj && !IsEmpty(storeObj.chkDoctorObj.code) ? storeObj.chkDoctorObj.code : '';
      acterNa = storeObj && storeObj.chkDoctorObj && !IsEmpty(storeObj.chkDoctorObj.name) ? storeObj.chkDoctorObj.name : '';
      break;
    case '3':
      acterCode = storeObj && storeObj.testDoctorObj && !IsEmpty(storeObj.testDoctorObj.code) ? storeObj.testDoctorObj.code : '';
      acterNa = storeObj && storeObj.testDoctorObj && !IsEmpty(storeObj.testDoctorObj.name) ? storeObj.testDoctorObj.name : '';
      break;
    default:
      break;
  }
  //审核前判断申请项目是染色项目,染色结果是否存在数据(浏阳肌理)
  const stainingUrl = '/lab/maininfo/judgeStainingResult';
  const data = {
    rptGroup: form.rptGroup,
    sampleda: form.sampleda,
    sampleNo: form.sampleNo,
    reqNo: form.reqNo
  };
  await proxy.$http
    .get(stainingUrl, { params: data })
    .then((res: any) => {
      if (res.data) {
        proxy.$emit('IschkLoading', 1);
        chkData(form, e, acterCode, acterNa, isNextRow, isTreatPrint);
        return;
      } else {
        proxy
          .$confirm('染色节点下没有数据是否审核？', '提示', {
            cancelButtonClass: 'cancel-button',
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
          .then(() => {
            proxy.$emit('IschkLoading', 1);
            chkData(form, e, acterCode, acterNa, isNextRow, isTreatPrint);
          })
          .catch((err: any) => {
            // VxeMessage(err, VxeNotifyType.error);
          });
        proxy.$emit('IschkLoading', 2);
      }
    })
    .catch((err: any) => {
      VxeMessage('数据请求失败', VxeNotifyType.error);
    });
}
async function chkData(form, e, acterCode, acterNa, isNextRow, isTreatPrint) {
  const url = '/lab/maininfo/updateBacTestChkDoctorAfterAuth';
  await proxy.$http
    .post(url, { sampleNo: form.sampleNo, rptGroup: form.rptGroup, sampleda: form.sampleda, id: form.id, edtType: e.edtType, codeRange: e.codeRange, action: e.action, acterCode: acterCode, acterNa: acterNa })
    .then((res: any) => {
      //审核返回
      labMainInfoList.forEach((m, i) => {
        if (res && res.status && !IsEmpty(res.status.code) && res.status.code === 1 && res.data && res.data.curMainInfo && m.id === res.data.curMainInfo.id) {
          Object.assign(m, res.data.curMainInfo);
          if (labMainInfoList.length > 0) {
            /**判断审核后是否自动跳转下一个标本 【shtgzdxybb】*/
            const sysopt = getOptionValueByCodeRptGroupOption('shtgzdxybb');
            if (sysopt === '1' || sysopt === 1) {
              //跳转下一个标本
              const ii = i + 1;
              if (ii <= labMainInfoList.length - 1 && isNextRow) {
                /**有下一个标本 */
                const nrow = Object.assign({}, labMainInfoList[ii]);
                tableTestListRef.value?.setCurrentRow(nrow);
                tableTestListRef.value?.focus();
                handleRowClick({ row: nrow });
              } else if (ii >= labMainInfoList.length && isNextRow) {
                if (tableTestListRef.value) {
                  tableTestListRef.value?.setCurrentRow(m);
                  tableTestListRef.value?.focus();
                  handleRowClick({ row: m });
                }
              }
              /**不跳转下一个标本 */
              if (!isNextRow) {
                const nrow = Object.assign({}, labMainInfoList[i]);
                tableTestListRef.value?.setCurrentRow(nrow);
                tableTestListRef.value?.focus();
                handleRowClick({ row: nrow });
              }
            }

            //静默更新其他修改项
            if (sysopt !== '1' && sysopt !== 1) {
              if (tableTestListRef.value) {
                tableTestListRef.value?.setCurrentRow(m);
                tableTestListRef.value?.focus();
                handleRowClick({ row: m });
              }
            }
          }
        }
        if (res && res.data && res.data.uptedLabMainInfos && res.data.uptedLabMainInfos.length > 0) {
          const am = res.data.uptedLabMainInfos.filter((p) => p.id === m.id);
          if (am && am.length > 0) {
            Object.assign(m, am[0]);
          }
        }
      });

      /**审核后自动打印 */
      if (res && res.status && !IsEmpty(res.status.code) && res.status.code === 1 && res.data && res.data.curMainInfo) {
        const rptopt = getOptionValueByCodeRptGroupOption('shhzddy');
        if ((rptopt === '1' || rptopt === 1) && isTreatPrint) {
          proxy.$emit('printAfterChk', res.data.curMainInfo);
        }
      }

      if (res && res.status && !IsEmpty(res.status.code) && res.status.code !== 1 && !IsEmpty(res.status.msg)) {
        VxeMessage(`${res.status.msg}`, VxeNotifyType.error);
      }
      proxy.$emit('IschkLoading', 2);
    })
    .catch((err: any) => {
      proxy.$emit('IschkLoading', 2);
      VxeMessage('数据请求失败', VxeNotifyType.error);
    });
}
function getAddFeeCnt(data) {
  console.log(data);
  labMainInfoList.forEach((m, i) => {
    if (m.id == form.id) {
      if (data.bacDrugCnt > 0) {
        if (data.addFeeCnt > 0) {
          if (data.errorCnt > 0) {
            m.addFee = 2;
          } else {
            m.addFee = 0;
          }
        } else {
          m.addFee = 1;
        }
      } else {
        m.addFee = null;
      }
    }
  });
}
/**只刷新记录信息，不做行选中操作，因为中间结果 处理时 已经选中本行数据 【中间结果改变时会用到】
 * @param mainInfoId 检验记录主键
 */
function refreshMainInfoListM4(mainInfoId) {
  const url = '/lab/maininfo/findLabMaininfoBac';
  proxy.$http
    .get(url, { params: { id: mainInfoId, rptGroup: form.rptGroup, sampleDaStr: form.sampleda } })
    .then((res: any) => {
      if (res && res.data && res.data.length > 0) {
        let ci = labMainInfoList.findIndex((p) => p.id === mainInfoId);
        if (ci > -1) {
          Object.assign(labMainInfoList[ci], res.data[0]);
        }
      }
    })
    .catch((err: any) => {
      VxeMessage('搜索报告申请异常', VxeNotifyType.error);
    });
}
/**如果是多条件查询状态下,新增标本，如果符合多条件则更新列表，如果不符合多条件，则之刷新人员信息跟中间结果 */
function refreshMainInfoListM5(mainInfoId) {
  if (!isMultiFilterState()) {
    return;
  }
  let paramData = { rptGroup: form.rptGroup, sampleDaStr: form.sampleda } as any;
  if (state.value !== 0) {
    paramData.stateCode = state.value;
  }
  if (isSelfRpt.value === 1) {
    paramData.isSelf = isSelfRpt.value;
  }
  if (selPatType.value !== null) {
    paramData.patType = selPatType.value;
  }

  const url = '/lab/maininfo/findLabMaininfoBac';
  proxy.$http
    .get(url, { params: paramData })
    .then(async (res) => {
      if (res && res.status && !IsEmpty(res.status.code) && res.status.code === 1 && res.data && res.data.length > 0) {
        const i = res.data.findIndex((p) => p.id === mainInfoId);
        const ii = labMainInfoList.findIndex((p) => p.id === mainInfoId);
        if (i > -1) {
          //列表中已有,更新本条检验记录
          if (ii > -1) {
            const nrow = Object.assign(labMainInfoList[ii], res.data[i]);
            tableTestListRef.value?.setCurrentRow(nrow);
            tableTestListRef.value?.focus();
            handleRowClick({ row: nrow });
          } else {
            //列表中没有
            labMainInfoList.push(res.data[i]);
            await tableTestListRef.value?.reloadData(labMainInfoList);
            tableTestListRef.value?.setCurrentRow(res.data[i]);
            tableTestListRef.value?.focus();
            handleRowClick({ row: res.data[i] });
          }
        } else {
          //回调，更新病人信息，检验结果等,重新查询本条记录
          const _rows = await findLabMainInfoByPrimaryData(form.rptGroup, form.sampleda, form.sampleNo, mainInfoId);
          if (_rows && _rows.length > 0) {
            //form.id = _rows[0].id;
            proxy.$emit('onlyUpdatePatResultInfo', _rows[0]);
          }
          //
        }
      }
    })
    .catch((err) => { });
}

/**如果是多条件筛选状态下，上机，清空筛选条件后刷新列表不做选中操作 */
function refreshMainInfoListM6(callback) {
  loading.value = true;
  const url = '/lab/maininfo/findLabMaininfoBac';
  let paramData = { rptGroup: form.rptGroup, sampleDaStr: form.sampleda, testTimeS: searchForm.testTimeS, testTimeE: searchForm.testTimeE } as any;
  proxy.$http
    .get(url, { params: paramData })
    .then((res: any) => {
      labMainInfoList.length = 0;
      labMainInfoList.push(...mainInfoSort(res.data));
      if (callback) {
        callback();
      }
      loading.value = false;
    })
    .catch((err: any) => {
      loading.value = false;
      VxeMessage('搜索报告申请异常', VxeNotifyType.error);
    });
}

/**取消审核记录
 * @e 1,取消初审  2 取消审核
 */
function unChkMainInfo(e, authUser: any) {
  let ar = tableTestListRef.value?.getCurrentRecord();

  if (authUser) {
    ar.unChkDoctor = IsEmpty(authUser.code) ? '' : authUser.code;
    ar.unChkDoctorNa = IsEmpty(authUser.name) ? '' : authUser.name;
  }
  const url = '/lab/maininfo/unChkBacMainInfo';
  proxy.$http
    .post(url, ar)
    .then((res: any) => {
      //审核返回
      if (res && res.status && !IsEmpty(res.status.code) && res.status.code === 1 && res.data) {
        const am = labMainInfoList.findIndex((p) => p.id === res.data.id);
        if (am > -1) {
          Object.assign(labMainInfoList[am], res.data);
          if (labMainInfoList.length > 0) {
            if (tableTestListRef.value) {
              tableTestListRef.value?.setCurrentRow(labMainInfoList[am]);
              tableTestListRef.value?.focus();
              const _row = Object.assign({}, labMainInfoList[am]);
              handleRowClick({ row: _row });
            }
          }
        }
      } else if (res && res.status && !IsEmpty(res.status.code) && res.status.code !== 1) {
        VxeMessage(res.status.msg ? res.status.msg : '取消审核检验失败,请联系管理员', VxeNotifyType.error);
      } else if (res && res.status && !IsEmpty(res.status) && res.status === 500) {
        VxeMessage(res.message ? res.message : '取消审核检验失败,请联系管理员', VxeNotifyType.error);
      }
    })
    .catch((err: any) => {
      if (res && res.status && !IsEmpty(res.status) && res.status === 500) {
        VxeMessage(res.message ? res.message : '取消审核检验失败,请联系管理员', VxeNotifyType.error);
      } else {
        VxeMessage('取消检验失败', VxeNotifyType.error);
      }
    });
}

/**删除上机记录
 */
async function deleteMainInfo() {
  const ar = tableTestListRef.value?.getCurrentRecord();
  if (!ar || IsEmpty(ar) || IsEmpty(ar.sampleda)) {
    VxeMessage('请选中要删除的记录', VxeNotifyType.warning);
    return;
  }
  if (ar.isChk === 1) {
    VxeMessage('已初审,不允许删除', VxeNotifyType.warning);
    return;
  }
  if (ar.isChk === 2) {
    VxeMessage('已审核,不允许删除', VxeNotifyType.warning);
    return;
  }
  const type = await VXETable.modal.confirm('确定删除选中记录?'); /*不能改el  $confirm 回车事件冒泡你*/
  if (type === 'confirm') {
    const url = `/lab/maininfoBac/deleteMaininfoBacById`;
    let params = {
      id: ar.id,
      sampleda: ar.sampleda,
      rptGroup: ar.rptGroup,
      sampleNo: ar.sampleNo
    };
    proxy.$http
      .post(url, params)
      .then(async (res: any) => {
        //审核返回
        if (res && res.status && res.status.code && !IsEmpty(res.status.code) && res.status.code === 1) {
          const ci = tableTestListRef.value?.getRowIndex(ar);
          await tableTestListRef.value?.remove(ar);
          labMainInfoList.splice(ci, 1);
          if (ci <= labMainInfoList.length - 1) {
            tableTestListRef.value?.setCurrentRow(labMainInfoList[ci]);
            tableTestListRef.value?.focus();
            const _row = Object.assign({}, labMainInfoList[ci]);
            handleRowClick({ row: _row });
          }
        }
      })
      .catch((err: any) => {
        VxeMessage('取消检验失败', VxeNotifyType.error);
      });
  }
}
/**刷新检验记录
 */
function refreshMainInfoList() {
  let condition = {} as any;
  if (state.value !== 0) {
    condition.stateCode = state.value;
  }
  if (isSelfRpt.value === 1) {
    condition.isSelf = 1;
  }
  if (selPatType.value !== null) {
    condition.patType = selPatType.value;
  }
  findLabMaininfo(
    condition,
    () => {
      /**刷新样本时提示危急值 sxybstswjz*/
      const a = getOptionValueByCodeGlobalOption('sxybstswjz');
      if (a && (a === '1' || a === 1)) {
        proxy.$emit('tipsAlarmExist');
      }
    },
    IsEmpty(condition) ? false : true
  );
}
/**添加上机记录 */
async function addMaininfo(reqData: any) {
  if (IsEmpty(reqData.rptGroup) || IsEmpty(reqData.sampleda) || IsEmpty(reqData.sampleNo)) {
    return;
  }
  if (reqData !== null) {
    for (let prop in reqData) {
      form[prop] = reqData[prop];
    }
  }
  form['dataType'] = '2';
  const postRes = await new Promise((resolve, reject) => {
    proxy.$http
      .post('/lab/maininfo/insertMaininfoByReqNo', form)
      .then((res: any) => {
        resolve(res);
      })
      .catch((err: any) => {
        reject(err);
        //VxeMessage('数据存储异常', VxeNotifyType.error);
      });
  });
  if (postRes && postRes.status && postRes.status.code !== 1) {
    //VxeMessage(res.status.msg, VxeNotifyType.error);
    const type = await VXETable.modal.alert(`${form.reqNo}  ${postRes.status.msg}`, '提醒', { type: 'alert', cancelButtonText: null, confirmButtonText: '已知晓', showFooter: true, showConfirmButton: false, showCancelButton: true });
    if (type === 'confirm' || type !== 'confirm' || type === 'close') {
      return false;
    }
  } else if (postRes && postRes.status && postRes.status.code === 1) {
    appendMainInfoToList(postRes.data);
    /* 记录过程记录 */
    const a = localStorage.getItem('userInfo');
    const b = JSON.parse(a);
    const processLogData = {
      strainId: null,
      strainNo: null,
      strainName: null,
      maininfoId: postRes.data.id,
      wkFlwId: null,
      wkFlwNodeId: null,
      rptGroup: postRes.data.rptGroup,
      sampleda: formatDateTime(postRes.data.sampleda, 'yyyy-MM-dd 00:00:00'),
      sampleNo: postRes.data.sampleNo,
      testFlowNo: null,
      testNodeNo: null,
      content: `【${formatDateTime(new Date(), 'yyyy-MM-dd hh:mm:ss')}】由【${IsEmpty(b.realname) ? '' : b.realname}】扫码上机`,
      operatorDoctor: IsEmpty(b.username) ? '' : b.username
    };
    saveProcessLogs(processLogData);
    console.log('上机===>>');

    //自动打印标签
    const aa = getOptionValueByCodeGlobalOption('wswsmsjzddybq'); /**微生物扫码上机自动打印标签*/
    if (aa && (aa === '1' || aa === 1)) {
      proxy.$emit('autoPrint');
    }
    //proxy.$emit('autoPrint');
  } else {
    VxeMessage('请求错误', VxeNotifyType.error);
  }
  /* 
  
  proxy.$http
        .post('/lab/maininfo/insertMaininfoByReqNo', form)
        .then(async (res: any) => {
          if (res && res.status && res.status.code !== 1) {
            //VxeMessage(res.status.msg, VxeNotifyType.error);
            const type = await VXETable.modal.alert(`${res.status.msg}`, '提醒', { type: 'alert', cancelButtonText: null, confirmButtonText: '已知晓', showFooter: true, showConfirmButton: false, showCancelButton: true });
            console.log('------->>>', type);
            if (type === 'confirm' || type !== 'confirm' || type === 'close') {
              resolve(false);
            }
          } else if (res && res.status && res.status.code === 1) {
            appendMainInfoToList(res.data);
          } else {
            VxeMessage('请求错误', VxeNotifyType.error);
          }
        })
        .catch((err: any) => {
          VxeMessage('数据存储异常', VxeNotifyType.error);
        });
  */
}
/**更新上机记录 */
function updateMaininfo(row) {
  let data = {
    rptGroup: row.rptGroup,
    sampleNo: row.sampleNo,
    sampleda: row.sampleda,
    labMaininfo: row
  };
  proxy.$http
    .post('/lab/maininfo/updateMaininfo', data)
    .then((res: any) => {
      if (res && res.status && res.status.code !== 1) {
        VxeMessage(res.status.msg, VxeNotifyType.error);
      } else if (res && res.status && res.status.code === 1) {
        const i = labMainInfoList.findIndex((p) => p.id === row.id);
        if (i > -1) {
          Object.assign(labMainInfoList[i], res.data);
        } else {
          Object.assign(row, res.data);
        }
        /* 记录过程记录 */
        const a = localStorage.getItem('userInfo');
        const b = JSON.parse(a);
        const processLogData = {
          strainId: null,
          strainNo: null,
          strainName: null,
          maininfoId: res.data.id,
          wkFlwId: null,
          wkFlwNodeId: null,
          rptGroup: res.data.rptGroup,
          sampleda: formatDateTime(res.data.sampleda, 'yyyy-MM-dd 00:00:00'),
          sampleNo: res.data.sampleNo,
          testFlowNo: null,
          testNodeNo: null,
          content: `【${formatDateTime(new Date(), 'yyyy-MM-dd hh:mm:ss')}】由【${IsEmpty(b.username) ? '' : b.username}】修改上机记录`,
          operatorDoctor: IsEmpty(b.username) ? '' : b.username
        };
        saveProcessLogs(processLogData);
      } else {
        VxeMessage('请求错误', VxeNotifyType.error);
      }
    })
    .catch((err: any) => {
      VxeMessage('更新检验记录失败,请联系管理员', VxeNotifyType.error);
    });
}
/**单元格样式
 *【1】是否启用系统选项颜色配置  encolorsetting
 *【1】急背景色  isurgentcolor
 *【2】打背景色  isprintcolor
 *【3】自助机打印背景色  isautoprintcolor
 *【4】审核背景色  ischkcolor
 *【5】危急值背景色  isalarmcolor
 *【6】门诊类型病人列表颜色  mzpattypecolor
 *【7】住院类型病人列表颜色  zypattypecolor
 *【8】急诊类型病人列表颜色  jzpattypecolor
 *【9】体检类型病人列表颜色  tjpattypecolor
 *【10】其他类型病人列表颜色  qtpattypecolor
 */
function cellClassName({ row, rowIndex, $rowIndex, column, columnIndex, $columnIndex }) {
  let patTypeColor = '';
  if (column && !IsEmpty(column.fixed)) {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      if (row && row.patType === '1') {
        //门诊
        const b = getOptionValueByCodeGlobalOption('mzpattypecolor');
        if (!IsEmpty(b)) {
          patTypeColor = b;
        }
      } else if (row && row.patType === '2') {
        //急诊
        const b = getOptionValueByCodeGlobalOption('jzpattypecolor');
        if (!IsEmpty(b)) {
          patTypeColor = b;
        }
      } else if (row && row.patType === '3') {
        //住院
        const b = getOptionValueByCodeGlobalOption('zypattypecolor');
        if (!IsEmpty(b)) {
          patTypeColor = b;
        }
      } else if (row && row.patType === '4') {
        //体检
        const b = getOptionValueByCodeGlobalOption('tjpattypecolor');
        if (!IsEmpty(b)) {
          patTypeColor = b;
        }
      } else {
        //其他
        if (!IsEmpty(row.patType)) {
          const b = getOptionValueByCodeGlobalOption('qtpattypecolor');
          if (!IsEmpty(b)) {
            patTypeColor = b;
          }
        }
      }
    }
  }
  if (column.property === 'isUrgent') {
    if (row.isUrgent === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('isurgentcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff', padding: '0', margin: '0' };
        }
      }
      return { background: '#FF0000', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column.property === 'isChk') {
    if (row.isChk === 2) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('ischkcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#008000', color: '#fff' };
    } else if (row.isChk === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('ischkcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#00FF00', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column.property === 'isAlarm') {
    if (row.isAlarm === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('isalarmcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#FF9900', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column.property === 'isMdr') {
    if (row.isMdr === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('ismdrcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#EB920A', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column.property === 'addFee') {
    if (row.addFee === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('addfeecolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#FF0000', color: '#fff' };
    } else if (row.addFee === 0) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('addfeeEdcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: 'green', color: '#fff' };
    } else if (row.addFee === 2) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('addfeeErrorcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#FFDCA6', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column.property === 'isAutoPrint') {
    if (row.isAutoPrint === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('isautoprintcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#800080', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column.property === 'isPrint') {
    if (row.isPrint === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('isprintcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#000080', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column && column.type && column.type === 'seq') {
    const a = formatDateTime(row.sampleda, 'dd');
    const b = Number(a);
    return { color: '#fff !important', backgroundColor: color31Array[b - 1], padding: '0 2px' };
  }
  return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
}
/**上机记录添加成功，列表中最后一条补一条
 * @row 新增的检验记录
 */
function appendMainInfoToList(row) {
  labMainInfoList.push({ ...row });
  labMainInfoList = mainInfoSort(labMainInfoList);
  if (tableTestListRef.value) {
    proxy.$nextTick(() => {
      setTimeout(async () => {
        await tableTestListRef.value?.scrollToRow(labMainInfoList[labMainInfoList.length - 1]);
      }, 500);
    });
  }
}
function closeShowPull() {
  showPull.value = false;
}
/**筛选条件发生改变 */
function conditionSelectChange() {
  let condition = { stateCode: state.value } as any;
  if (isSelfRpt.value === 1) {
    condition.isSelf = 1;
  }
  if (selPatType.value !== null) {
    condition.patType = selPatType.value;
  }
  if (!IsEmpty(searchForm.patNo)) {
    condition.patNo = searchForm.patNo;
  }
  if (!IsEmpty(searchForm.patNa)) {
    condition.patNa = searchForm.patNa;
  }
  if (!IsEmpty(searchForm.sampleType)) {
    condition.sampleType = searchForm.sampleType;
  }
  if (!IsEmpty(searchForm.reqPurposeId)) {
    condition.reqPurposeId = searchForm.reqPurposeId;
  }
  if (!IsEmpty(searchForm.testTimeS)) {
    condition.testTimeS = searchForm.testTimeS;
  }
  if (!IsEmpty(searchForm.testTimeE)) {
    condition.testTimeE = searchForm.testTimeE;
  }
  if (!IsEmpty(searchForm.chkTimeS)) {
    condition.chkTimeS = searchForm.chkTimeS;
  }
  if (!IsEmpty(searchForm.chkTimeE)) {
    condition.chkTimeE = searchForm.chkTimeE;
  }

  if (!IsEmpty(searchForm.isFilter)) {
    condition.isFilter = searchForm.isFilter;
  }
  if (!IsEmpty(searchForm.isPositive)) {
    condition.isPositive = searchForm.isPositive;
  }
  if (!IsEmpty(searchForm.isStaining)) {
    condition.isStaining = searchForm.isStaining;
  }
  if (!IsEmpty(searchForm.queryDay)) {
    condition.queryDay = searchForm.queryDay;
  }
  if (!IsEmpty(searchForm.isExperiment)) {
    condition.isExperiment = searchForm.isExperiment;
  }
  showPull.value = false;
  findLabMaininfo(condition, null, true);
}

function searchConfirm() {
  searchForm.isFilter = true;
  conditionSelectChange();
}
/**查询全部 */
function searchAll() {
  state.value = 0;
  isSelfRpt.value = 0;
  selPatType.value = null;
  searchForm.patNo = '';
  searchForm.patNa = '';
  searchForm.sampleType = '';
  searchForm.reqPurposeId = '';
  searchForm.chkTimeS = '';
  searchForm.chkTimeE = '';
  searchForm.isFilter = false;
  searchForm.isExperiment = 0;
  searchForm.isPositive = '1';
  searchForm.isStaining = '2';
  searchForm.queryDay = null;
  conditionSelectChange();
}
/**获取报告申请
 * @form rptGroup,sampleda,sampleNo,reqNo 参数实体
 * @callback 请求数据成功后的回调函数
 **/
function findLabMaininfo(mainInfo, callback, isMultiConditions = false) {
  loading.value = true;
  labMainInfoList.length = 0;
  const url = '/lab/maininfo/findLabMaininfoBac';
  let paramData = { rptGroup: form.rptGroup, sampleDaStr: form.sampleda } as any;
  if (isMultiConditions) {
    if (mainInfo && !IsEmpty(mainInfo.stateCode)) {
      paramData.stateCode = mainInfo.stateCode;
    }
    if (mainInfo && !IsEmpty(mainInfo.isSelf)) {
      paramData.isSelf = mainInfo.isSelf;
    }
    if (mainInfo && !IsEmpty(mainInfo.patType)) {
      paramData.patType = mainInfo.patType;
    }
    if (mainInfo && !IsEmpty(mainInfo.patType)) {
      paramData.patType = mainInfo.patType;
    }
    if (mainInfo && !IsEmpty(mainInfo.patNo)) {
      paramData.patNo = mainInfo.patNo;
    }
    if (mainInfo && !IsEmpty(mainInfo.patNa)) {
      paramData.patNa = mainInfo.patNa;
    }
    if (mainInfo && !IsEmpty(mainInfo.sampleType)) {
      paramData.sampleType = mainInfo.sampleType;
    }
    if (mainInfo && !IsEmpty(mainInfo.reqPurposeId)) {
      paramData.reqPurposeId = mainInfo.reqPurposeId;
    }
    if (mainInfo && !IsEmpty(mainInfo.testTimeE)) {
      paramData.testTimeE = mainInfo.testTimeE;
    }
    if (mainInfo && !IsEmpty(mainInfo.testTimeS)) {
      paramData.testTimeS = mainInfo.testTimeS;
    }
    if (mainInfo && !IsEmpty(mainInfo.chkTimeS)) {
      paramData.chkTimeS = mainInfo.chkTimeS;
    }
    if (mainInfo && !IsEmpty(mainInfo.chkTimeE)) {
      paramData.chkTimeE = mainInfo.chkTimeE;
    }
    if (mainInfo && !IsEmpty(mainInfo.isFilter)) {
      paramData.isFilter = mainInfo.isFilter;
    }
    if (mainInfo && !IsEmpty(mainInfo.isPositive)) {
      paramData.isPositive = mainInfo.isPositive;
    }
    if (mainInfo && !IsEmpty(mainInfo.isStaining)) {
      paramData.isStaining = mainInfo.isStaining;
    }
    if (mainInfo && !IsEmpty(mainInfo.queryDay)) {
      paramData.queryDay = mainInfo.queryDay;
    }
    if (mainInfo && !IsEmpty(mainInfo.isExperiment)) {
      paramData.isExperiment = mainInfo.isExperiment;
    }
  }
  proxy.$http
    .get(url, { params: paramData })
    .then((res: any) => {
      labMainInfoList.push(...mainInfoSort(res.data));
      proxy.$emit('getLabMainInfoList', labMainInfoList);
      if (callback) {
        callback();
      }
      if (labMainInfoList.length > 0) {
        const $table = proxy.$refs.tableTestListRef as any;
        if ($table) {
          let selectList = labMainInfoList.find((item) => item.sampleNo === form.sampleNo);

          /**刷新后自动跳到____标本号 sxhtzdbbh */
          const a = getOptionValueByCodeRptGroupOption('sxhtzdbbh');

          /**刷新后跳到【最前】标本 */
          if (!IsEmpty(a) && (a === '0' || a === 0)) {
            selectList = labMainInfoList[0];
          }
          /**刷新后跳到【最后】标本*/
          if (!IsEmpty(a) && (a === '2' || a === 2)) {
            //selectList = labMainInfoList[labMainInfoList.length - 1];
            //查出当前日期的最后一条数据
            const llist = labMainInfoList.filter((a: any) => a.sampleda == form.sampleda);
            if (llist.length > 0) {
              selectList = llist[llist.length - 1];
            }
          }

          if (selectList === undefined) {
            loading.value = false;
            form.id = '';
            proxy.$emit('getReqRptResult', form);
            return;
          }

          // if (selectList === undefined && !isMultiConditions /*非多条件查询*/) {
          //   loading.value = false;
          //   form.id = '';
          //   proxy.$emit('getReqRptResult', form);
          //   return;
          // }

          // if (selectList === undefined && isMultiConditions /*多条件查询*/) {
          //   selectList = labMainInfoList[0];
          // }

          $table.setCurrentRow(selectList);
          $table.focus();
          handleRowClick({ row: selectList });
        }
      } else {
        proxy.$emit('mainInfoRowChange', null);
      }
      loading.value = false;
    })
    .catch((err: any) => {
      loading.value = false;
      VxeMessage('搜索报告申请异常', VxeNotifyType.error);
    });
}
/**按报告单元，检验日期，标本号查询数据库有没有记录 */
function findLabMainInfoByPrimaryData(rptGrpId, sampleda, sampleno, id = '') {
  return new Promise((resolve, reject) => {
    const url = '/lab/maininfo/findLabMaininfoBac';
    proxy.$http
      .get(url, { params: { rptGroup: rptGrpId, sampleDaStr: sampleda, sampleNo: sampleno, id: id } })
      .then((res: any) => {
        if (res && res.status && !IsEmpty(res.status.code) && res.status.code === 1 && res.data && res.data.length > 0) {
          resolve(res.data);
        } else {
          resolve(null);
        }
      })
      .catch((err: any) => {
        resolve(null);
      });
  });
}
/**按条码号没有记录 */
function findLabMainInfoByReqNo(rptGroup, reqNo) {
  return new Promise((resolve, reject) => {
    const url = '/lab/maininfo/findLabMaininfoByReqNo';
    proxy.$http
      .get(url, { params: { reqNo: reqNo, rptGroup: rptGroup } })
      .then((res: any) => {
        if (res && res.status && !IsEmpty(res.status.code) && res.status.code === 1 && res.data && res.data.length > 0) {
          resolve(res.data);
        } else {
          resolve(null);
        }
      })
      .catch((err: any) => {
        resolve(null);
      });
  });
}
/**行点击事件 */
function handleRowClick({ row }: any) {
  console.log('切换标本======');

  form.id = IsEmpty(row.id) ? '' : row.id;
  form.sampleNo = row.sampleNo;
  form.rptGroup = row.rptGroup;
  form.reqNo = row.reqNo;
  form.sampleda = row.sampleda;
  proxy.$nextTick(() => {
    if (tableTestListRef.value) {
      setTimeout(async () => {
        await tableTestListRef.value?.setCurrentRow(row);
        await tableTestListRef.value?.scrollToRow(row);
        tableTestListRef.value?.focus();
      }, 50);
    }
    proxy.$emit('mainInfoRowChange', row);
  });
}
/**检验记录有信息变化，同步信息处理 */
function updateMainInfoRow(row) {
  if (IsEmpty(row)) {
    return;
  }
  const index = labMainInfoList.findIndex((p) => {
    return p.id === row.id;
  });
  if (index > -1) {
    Object.assign(labMainInfoList[index], row);
  } else {
    refreshMainInfoListM2({ isSelCurRow: true, isRefreshRptResult: true, mainInfoId: row.id });
  }
  proxy.$forceUpdate();
}
/**编辑右侧病人信息
 * @type 发生改变的值
 * →【1】报告单元值变化;
 * →【2】检验日期值发生变化
 * →【3】标本号值发生变化
 * →【4】条码号值发生变化
 * @value 发生变化后的值
 * @formDataObj form对象所有值
 */
async function baseInfoChange(type, value, formDataObj, callback) {
  if (IsEmpty(type)) {
    return;
  }
  switch (type) {
    case 1:
      // console.log('走的1', type, value, formDataObj);
      break;
    case 2:
      // console.log('走的2', type, value, formDataObj);
      break;
    case 3:
      const index = labMainInfoList.findIndex((p) => {
        return p.sampleda === formDataObj.sampleda && p.sampleNo === `${value}`;
      });
      if (index > -1) {
        handleRowClick({ row: labMainInfoList[index] });
      } else {
        tableTestListRef.value?.setCurrentRow({});
        tableTestListRef.value?.scrollToRow(labMainInfoList[labMainInfoList.length - 1]);
        proxy.$emit('mainInfoRowChange', null);
        //proxy.$emit('getReqRptResult', null);
      }
      if (callback) {
        callback();
      }
      break;
    case 4:
      if (IsEmpty(value)) {
        //先检索列表中有没有该条码号
        const index = labMainInfoList.findIndex((p) => {
          return p.sampleda === formDataObj.sampleda && p.rptGroup === `${formDataObj.rptGroup}` && p.sampleNo === `${formDataObj.sampleNo}`;
        });
        if (index > -1) {
          //有：选中
          const rowObj = labMainInfoList[index];
          handleRowClick({ row: rowObj });
          if (rowObj && IsEmpty(rowObj.reqNo)) {
            rowObj.reqNo = value;
            updateMaininfo(rowObj);
            if (callback) {
              callback();
            }
          }
        } else {
          form.id = '';
          form.reqNo = value;
          form.rptGroup = formDataObj.rptGroup;
          form.sampleNo = formDataObj.sampleNo;
          form.sampleda = formDataObj.sampleda;
          if (!isMultiFilterState()) {
            addMaininfo(formDataObj);
            if (callback) {
              callback();
            }
          }
          if (isMultiFilterState()) {
            //先查询数据库有没有
            const isHasRow = await findLabMainInfoByPrimaryData(form.rptGroup, form.sampleda, form.sampleNo);
            //有，则之刷新病人信息，结果列表
            if (isHasRow && isHasRow.length > 0) {
              proxy.$emit('onlyUpdatePatResultInfo', isHasRow[0]);
            }
            //无，则创建
            if (!isHasRow || isHasRow.length <= 0) {
              //先清空条件筛选
              state.value = 0;
              isSelfRpt.value = 0;
              selPatType.value = null;
              let condition = { stateCode: state.value } as any;
              if (isSelfRpt.value === 1) {
                condition.isSelf = 1;
              }
              if (selPatType.value !== null) {
                condition.patType = selPatType.value;
              }
              refreshMainInfoListM6(() => {
                //addMaininfo(formDataObj);
                baseInfoChange(type, value, formDataObj, callback);
                return;
              }, false);
            }
          }
        }
      } else {
        //先检索列表中有没有该条码号
        const index = labMainInfoList.findIndex((p) => {
          return p.sampleda === formDataObj.sampleda && p.rptGroup === `${formDataObj.rptGroup}` && p.sampleNo === `${formDataObj.sampleNo}` && p.reqNo === `${formDataObj.reqNo}`;
        });
        if (index > -1) {
          //有：选中
          const rowObj = labMainInfoList[index];
          handleRowClick({ row: rowObj });
          if (rowObj && IsEmpty(rowObj.reqNo)) {
            rowObj.reqNo = value;
            updateMaininfo(rowObj);
          } else {
            const type = await VXETable.modal.confirm('该标本号已有病人信息, 是否继续？'); /*不能改el  $confirm 回车事件冒泡*/
            if (type === 'confirm') {
              //选中
              //继续上机
              rowObj.reqNo = value;
              updateMaininfo(rowObj);
            }
          }
          if (callback) {
            callback();
          }
        } else {
          //先后端验证有无上机
          const isHasRow = await findLabMainInfoByPrimaryData(formDataObj.rptGroup, formDataObj.sampleda, formDataObj.sampleNo);
          //1、有则提示
          if (isHasRow && isHasRow.length > 0) {
            let str = '';
            isHasRow.forEach((element) => {
              str += '→  报告单元:' + element.rptGroupNa + '\u0020\u0020\u0020\u0020上机日期:' + element.sampleda + '\u0020\u0020\u0020\u0020 标本号:' + element.sampleNo + '\n';
            });
            const type = await VXETable.modal.confirm(`标本号已使用,相关信息如下:\n  ${str} \n 是否继续？`); /*不能改el  $confirm 回车事件冒泡你*/
            if (type === 'confirm') {
              //选中
              //继续上机
              isHasRow[0].reqNo = value;
              updateMaininfo(isHasRow[0]);
            }
            return;
          }

          //检查条码号是否上机
          const reqNoList = await findLabMainInfoByReqNo(formDataObj.rptGroup, formDataObj.reqNo);
          if (reqNoList && reqNoList.length > 0) {
            let str = '';
            reqNoList.forEach((element) => {
              str += '→  报告单元:' + element.rptGroupNa + '\u0020\u0020\u0020\u0020上机日期:' + element.sampleda + '\u0020\u0020\u0020\u0020 标本号:' + element.sampleNo + '\n';
            });
            const type = await VXETable.modal.confirm(`条码【${formDataObj.reqNo}】被重复使用,相关信息如下：\n  ${str}`); /*不能改el  $confirm 回车事件冒泡你*/
            if (type !== 'confirm') {
              if (callback) {
                callback(false);
              }
              return;
            }
          }

          //2、无：新增
          if (!isHasRow || isHasRow.length <= 0) {
            form.id = '';
            form.reqNo = value;
            form.rptGroup = formDataObj.rptGroup;
            form.sampleNo = formDataObj.sampleNo;
            form.sampleda = formDataObj.sampleda;
            if (isMultiFilterState()) {
              //先清空多条件筛选
              state.value = 0;
              isSelfRpt.value = 0;
              selPatType.value = null;
              let condition = { stateCode: state.value } as any;
              if (isSelfRpt.value === 1) {
                condition.isSelf = 1;
              }
              if (selPatType.value !== null) {
                condition.patType = selPatType.value;
              }
              refreshMainInfoListM6(() => {
                //addMaininfo(formDataObj);
                baseInfoChange(type, value, formDataObj, callback);
                return;
              }, false);
            } else {
              const addRes = await addMaininfo(formDataObj);
              if (callback) {
                callback(addRes);
              }
            }
          }
        }
      }

      break;
    default:
      break;
  }
}
/**右键菜单事件
 * @param menu 菜单对象
 * @param row 右键行对象
 * @param column 右键列对象
 */
function contextMenuClickEvent({ menu, row, column }) {
  switch (menu.code) {
    case 'Reload':
      refreshMainInfoList();
      break; //
    case 'Delete':
      deleteMainInfo();
      break;
    case 'Copy':
      if (row && column) {
        if (!IsEmpty(row[column.field]) && XEClipboard.copy(row[column.field])) {
          VxeMessage('已将单元格内容复制到剪贴板', VxeNotifyType.success);
        } else {
          XEClipboard.copy('空');
        }
      }
      break;
    case 'Edit':
      if (testListEditRef.value) {
        testListEditRef.value?.initPage(row);
      }
      break;
    case 'DeleteMany':
      if (testListBatchHandleRef.value) {
        testListBatchHandleRef.value?.initPage(row, menu, form.sampleda, form.rptGroup, 2);
        searchConfirm();
      }
      break;
    case 'FirstReviewMany':
      if (testListBatchHandleRef.value) {
        testListBatchHandleRef.value?.initPage(row, menu, form.sampleda, form.rptGroup, 2);
      }
      break;
    case 'ReviewMany':
      if (testListBatchHandleRef.value) {
        testListBatchHandleRef.value?.initPage(row, menu, form.sampleda, form.rptGroup, 2);
      }
      break;
    case 'PrintMany':
      if (testListBatchHandleRef.value) {
        testListBatchHandleRef.value?.initPage(row, menu, form.sampleda, form.rptGroup, 2);
      }
      break;
    case 'CancelTest':
      noticeHisRefound(row);
      break;
    default:
      break;
  }
}
/**切换模板面板显示
 */
function toggleItemTemplatePanel() {
  isShowItemTemplatePanel.value = !isShowItemTemplatePanel.value;
}
/**标本号修改成功返回 */
function mainInfoUptSuccess(row) {
  if (tableTestListRef.value) {
    const i = labMainInfoList.findIndex((p) => p.id === row.id); //tableTestListRef.value?.getRowIndex(row);
    if (i !== -1) {
      Object.assign(labMainInfoList[i], row);
      mainInfoSort(labMainInfoList);
      const ii = labMainInfoList.findIndex((p) => p.id === row.id);
      proxy.$forceUpdate();
      proxy.$nextTick(async () => {
        handleRowClick({ row: labMainInfoList[ii] });
        if (tableTestListRef.value) {
          await tableTestListRef.value?.reloadData(labMainInfoList);
        }
      });
    }
  }
}
/**批量操作完成
 * @param rows 本次批量操作完成行集合
 */
function mainInfoBatchUptSuccess(rows) {
  let ci = -1;
  if (tableTestListRef.value) {
    const r = tableTestListRef.value?.getCurrentRecord();
    ci = tableTestListRef.value?.getRowIndex(r); //labMainInfoList.findIndex(p => p.id === r.id);//
  }
  labMainInfoList.forEach((m) => {
    rows.forEach((op) => {
      if (m.id === op.id) {
        Object.assign(m, op);
      }
    });
  });
  proxy.$forceUpdate();
  proxy.$nextTick(async () => {
    if (tableTestListRef.value) {
      await tableTestListRef.value?.reloadData(labMainInfoList);
      if (ci > 0) {
        handleRowClick({ row: labMainInfoList[ci] });
      }
    }
  });
}
/**定位回车触发
 * @param e 事件源
 */
function keyValueAnchorKeyDown(e) {
  if (e && e.$event && !IsEmpty(e.$event.keyCode) && e.$event.keyCode === 13 && !IsEmpty(e.value)) {
    //执行搜索
    const a = labMainInfoList.filter((p) => (p.patNa && p.patNa.includes(keyValueAnchor.value)) || (p.reqNo && p.reqNo.includes(keyValueAnchor.value)) || (p.patNo && p.patNo.includes(keyValueAnchor.value)) || (p.bedNo && p.bedNo.includes(keyValueAnchor.value)));
    if (a && a.length > 0) {
      if (anchorKeyDownCount.value <= a.length - 1) {
        handleRowClick({ row: a[anchorKeyDownCount.value] });
        anchorKeyDownCount.value++;
      } else {
        anchorKeyDownCount.value = 0;
        handleRowClick({ row: a[0] });
      }
    } else {
      anchorKeyDownCount.value = 0;
    }
  }
}

async function noticeHisRefound(row: any) {
  const ar = tableTestListRef.value?.getCurrentRecord();
  if (row.isChk == '2') {
    VxeMessage('标本已上机禁止取消', VxeNotifyType.error);
    return;
  }
  const data = { id: row.id };
  const url = '/lab/maininfo/noticeHisRefound';
  proxy.$http
    .post(url, data)
    .then(async (res: any) => {
      if (res && res.status && res.status.code && res.status.code === 100) {
        //有其他上机记录，需要弹窗处理
        //查看是否有已审核的数据
        VxeMessage('有其他上机记录，请先删除后再取消上机', VxeNotifyType.error);
        return;
      }

      const ci = tableTestListRef.value?.getRowIndex(ar);
      await tableTestListRef.value?.remove(ar);
      labMainInfoList.splice(ci, 1);
      if (ci <= labMainInfoList.length - 1) {
        tableTestListRef.value?.setCurrentRow(labMainInfoList[ci]);
        tableTestListRef.value?.focus();
        const _row = Object.assign({}, labMainInfoList[ci]);
        handleRowClick({ row: _row });
      } else {
        handleRowClick({ row: labMainInfoList.length > 0 ? labMainInfoList[labMainInfoList.length - 1] : null });
      }
      VxeMessage(res.status.msg, VxeNotifyType.success);
    })
    .catch((err: any) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}
/**锚点定位关键字发生改变
 *
 */
function keyValueAnchorChange(e) {
  anchorKeyDownCount.value = 0;
}
/**是否是条件状态 */
function isMultiFilterState() {
  if (!IsEmpty(state.value) && state.value != 0) {
    return true;
  }
  if (!IsEmpty(selPatType.value) && selPatType.value != null) {
    return true;
  }
  if (!IsEmpty(isSelfRpt.value) && isSelfRpt.value != 0) {
    return true;
  }
  return false;
}

let sampleTypeList: any = reactive([]);
function findSampleTypeList() {
  sampleTypeList.length = 0; //放入数据前清空数据

  const url = '/api/lab/labSampleType/findSampleTypeList';
  proxy.$http
    //注意此处的数据条数
    .get(url, {
      params: { seachValue: '' }
    })
    .then((res: any) => {
      if (res.data.length > 0) {
        sampleTypeList.push({ sampleTypeCode: '', sampleTypeName: '全部' });
        sampleTypeList.push(...res.data);
      }
    })
    .catch((err: any) => {
      VxeMessage('获取左侧仪器表格数据异常', VxeNotifyType.error);
    });
}
let reqPurposeList: any = reactive([]);
function findReqPurposeList() {
  reqPurposeList.length = 0; //放入数据前清空数据

  const url = '/api/bac/bacReqPurpose/findPurposeList';
  proxy.$http
    //注意此处的数据条数
    .get(url, {
      params: { seachValue: '' }
    })
    .then((res: any) => {
      if (res.data.length > 0) {
        reqPurposeList.push({ id: '', purposeName: '全部' });
        reqPurposeList.push(...res.data);
      }
    })
    .catch((err: any) => {
      VxeMessage('获取左侧仪器表格数据异常', VxeNotifyType.error);
    });
}

watch(
  () => storeObj.bloodResultFlag,
  (n, o) => {
    if (IsEmpty(n) || n <= 0) {
      return;
    }
    RefreshWKLResultsQuiert();
  },
  { deep: true, immediate: false }
);

function RefreshWKLResultsQuiert() {
  if (!IsEmpty(storeObj.maininfoObj)) {
    let curMainInfo: any = storeObj.maininfoObj;
    //根据ID 查看列表中是否存在此数据
    //如果存在更新
    //如果不存在则新增
    const i = labMainInfoList.findIndex((p) => p.id === curMainInfo.id);
    if (i > -1) {
      //根据id查询
      const url = '/lab/maininfoBac/findMainInfoById';
      proxy.$http
        //注意此处的数据条数
        .get(url, {
          params: {
            id: curMainInfo.id
          }
        })
        .then((res: any) => {
          if (res.status.code === 1) {
            const mainObj = res.data;
            Object.assign(labMainInfoList[i], mainObj);
            if (form.id == curMainInfo.id) {
              handleRowClick({ row: labMainInfoList[i] });
            }
          }
        })
        .catch((err: any) => {
          // VxeMessage('获取获取当前字典的规则列表失败',VxeNotifyType.error)
        });
    } else {
      if (curMainInfo.sampleda == form.sampleda && curMainInfo.rptGroup == form.rptGroup && curMainInfo.orgId == form.orgId) {
        //根据id查询
        const url = '/lab/maininfoBac/findMainInfoById';
        proxy.$http
          //注意此处的数据条数
          .get(url, {
            params: {
              id: curMainInfo.id
            }
          })
          .then((res: any) => {
            if (res.status.code === 1) {
              const mainObj = res.data;
              appendMainInfoToList(mainObj);
            }
          })
          .catch((err: any) => {
            // VxeMessage('获取获取当前字典的规则列表失败',VxeNotifyType.error)
          });
      }
    }
  }
}
</script>
<style lang="scss" scoped>#testlistpanel {
  height: 100%;

  .footer-vxe-toolbar {
    padding: 0.3em !important;
  }

  :deep(.footer-vxe-toolbar .vxe-input--inner) {
    line-height: unset !important;
    height: 95% !important;
  }
}

.my-dropdown3 {
  .button-blue {
    margin: 5px 5px 5px 0;
  }
}

//初审
:deep(.is-first-reviewed) {
  content: '初' !important;
}

:deep(.is-first-reviewed::after) {
  content: '初' !important;
  color: #fff !important;
}

:deep(.flag-cell) {
  .vxe-cell {
    padding: 0 2px !important;
  }
}</style>
